package com.sunrate.investingquote.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunrate.investingquote.bean.Srcrate;
import com.sunrate.investingquote.mapper.SrcrateMapper;
import org.springframework.stereotype.Service;

import java.util.Collection;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 作者
 * @since 2023-06-15 14:57:27
 */
@Service
public class SrcrateDao extends ServiceImpl<SrcrateMapper, Srcrate> {

    public Integer insertBatchSomeColumn(Collection<Srcrate> entityList) {
        return baseMapper.insertBatchSomeColumn(entityList);
    }

    public Srcrate getBySrcIdAndPrdId(String prdId, String srcId) {
        LambdaQueryWrapper<Srcrate> wrapper = Wrappers.lambdaQuery(Srcrate.class)
                .eq(Srcrate::getPrdId, prdId)
                .eq(Srcrate::getSrcId, srcId);
        return baseMapper.selectOne(wrapper);
    }


    public boolean saveOrUpdateQuote(Srcrate entity) {
        LambdaUpdateWrapper<Srcrate> luw = new LambdaUpdateWrapper<Srcrate>()
                .set(Srcrate::getSrcAsk, entity.getSrcAsk())
                .set(Srcrate::getSrcBid, entity.getSrcBid())
                .set(Srcrate::getSrcMid, entity.getSrcMid())
                .set(Srcrate::getSrcSpread, entity.getSrcSpread())
                .set(Srcrate::getLastDatetime, entity.getLastDatetime())
                .set(Srcrate::getSrcDatetime, entity.getSrcDatetime())
                .eq(Srcrate::getSrcId, entity.getSrcId())
                .eq(Srcrate::getPrdId, entity.getPrdId());
        return this.saveOrUpdate(null, luw);
    }


}
